<template>
  <view class="custom-tab-bar">
    <view class="tab-bar-container">
      <view 
        v-for="(item, index) in list" 
        :key="index"
        class="tab-bar-item"
        @click="switchTab(item, index)"
      >
        <view class="tab-bar-icon">
          <view 
            class="icon-block"
            :class="{ 'active': current === index }"
          ></view>
          <image 
            :src="current === index ? item.selectedIconPath : item.iconPath"
            class="icon"
            :class="{ 'active': current === index }"
          />
        </view>
        <text class="tab-bar-text">{{ item.text }}</text>
      </view>
    </view>
  </view>
</template>

<script setup>
import { ref, onMounted } from 'vue';

const props = defineProps({
  current: {
    type: Number,
    default: 0
  }
});

const list = [
  {
    pagePath: "pages/index/index",
    text: "首页",
    iconPath: "/static/icon0.png",
    selectedIconPath: "/static/activeicon0.png"
  },
  {
    pagePath: "pages/other/forum/index",
    text: "论坛",
    iconPath: "/static/icon1.png",
    selectedIconPath: "/static/activeicon3.png"
  },
  {
    pagePath: "pages/shop/index",
    text: "文创",
    iconPath: "/static/icon2.png",
    selectedIconPath: "/static/activeicon1.png"
  },
  {
    pagePath: "pages/user/index",
    text: "我的",
    iconPath: "/static/icon3.png",
    selectedIconPath: "/static/activeicon4.png"
  }
];

const switchTab = (item, index) => {
  if (props.current === index) return;
  uni.switchTab({
    url: '/' + item.pagePath
  });
};
</script>

<style lang="scss" scoped>
.custom-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #6c8380;
  display: flex;
  align-items: center;
  padding: 0 20px;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.tab-bar-container {
  display: flex;
  justify-content: space-around;
  width: 100%;
}

.tab-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  flex: 1;
}

.tab-bar-icon {
  position: relative;
  width: 30px;
  height: 30px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.icon-block {
  position: absolute;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  transition: all 0.3s ease;
  
  &.active {
    width: 40px;
    height: 40px;
  }
}

.icon {
  width: 24px;
  height: 24px;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
  
  &.active {
    width: 28px;
    height: 28px;
  }
}

.tab-bar-text {
  font-size: 12px;
  color: #ffffff;
  margin-top: 4px;
}
</style> 